package com.zeta.plan.utils;


public class RandomString {
    private static final String str = "qwertyuiopasdfghjklzxcvbnm0123456789ZXCVBNMASDFGHJKLPOIUYTREWQ";
    private static final int defaultLength = 6;

    /**
     * 生成指定长度的随机字符串
     * @param length
     * @return
     */
    public static String createRandomString(int length) {
        if (length > str.length() || length <= 0) {
            length = defaultLength;
        }
        StringBuilder sb = new StringBuilder();

        for (int i = 0; i < length; i++) {
            int index = (int) (Math.random() * (str.length()));
            sb.append(str.charAt(index));
        }

        return sb.toString();
    }
}
